<?php
namespace app\common\controller;

use basic\AdminBase;
use think\facade\Db;
use think\facade\View;

class CommonBase extends AdminBase
{
    /**
     * 析构函数
     */
    function __construct()
    {
        header("Cache-control: private");  // history.back返回后输入框值丢失问题
        parent::__construct();
        $this->initialize();
        request()->isAjax() ? define('IS_AJAX',true) : define('IS_AJAX',false);  //
        (request()->isGet()) ? define('IS_GET',true) : define('IS_GET',false);  //
        (request()->isPost()) ? define('IS_POST',true) : define('IS_POST',false);  //
        //如果自定义了模型，按照自定的来

        //系统开关
        if(tpCache('shop_info.sys_close') && MODULE_NAME!='admin' && ACTION_NAME!='weihu'){
            $this->redirect(url('mobile/index/weihu'));
        }
        if(defined('USER_ROLE') && USER_ROLE=='supplier'){
            $this->redirect(url('admin/admin/yiqigou'));
        }

        //配置文件
        $tpshop_config = array();
        $tp_config = Db::name('config')->cache(true)->select();
        foreach ($tp_config as $k => $v) {
            if ($v['name'] == 'hot_keywords') {
                $tpshop_config['hot_keywords'] = explode('|', $v['value']);
            }
            $tpshop_config[$v['inc_type'] . '_' . $v['name']] = $v['value'];
        }
        View::assign('tpshop_config', $tpshop_config);
        View::assign('qq_map_key',$this->qq_map_key);
    }

    public function initialize()
    {
        parent::initialize();
    }
    function ajaxReturn($data)
    {
        if($_COOKIE['language']=='en'){
            $tr =new \app\common\behavior\Translation();
            $tr->run($data);
        }
        exit(json_encode($data));
    }
}